<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%><%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<tiles:insertDefinition name="layout">
	<tiles:putAttribute name="head">
		<style type="text/css">
#selColors option {
	padding: 0.2em;
	margin: 0.2em;
}

.courseType {
	padding: 0.4em;
}

.dialogForm {
	display: none;
}
</style>
		<script type="text/javascript">
			$(function() {
				$(".confirm").confirmDialog(function(data) {
					helper.showMsg(data, {
						okHandler : function() {
							location.reload();
						}
					});
				});

				$("form").Validform({
					ajaxPost : true,
					tiptype : ValidUtils.siblingTip,
					callback : function(data) {
						helper.showMsg(data, {
							okHandler : function() {
								location.reload();
							}
						});
					}
				});

				$(".showDialog").click(function() {
					var form = $(this).closest("tr").find(".dialogForm").get(0);
					art.dialog({
						content : form
					});

					return false;
				});
			});
		</script>
	</tiles:putAttribute>
	<tiles:putAttribute name="mainBody">
		<form class="form-horizontal" action="doCreateDepartment" method="post">
			<fieldset>
				<legend>部门列表</legend>
			</fieldset>
			<div class="control-group">
				<div class="control-group">
					<div class="control-label">新部门名称</div>
					<div class="controls">
						<input type="text" name="name" />
					</div>
				</div>
				<div class="controls">
					<button class="btn btn-primary">创建</button>
				</div>
			</div>
		</form>
		<table class="table">
			<thead>
				<tr>
					<th>名称</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody>
				<s:iterator value="departments" var="department">
					<tr>
						<td>${department}
							<form action="doModifyDepartment" class="form-inline dialogForm">
								<input type="hidden" name="id" value="${department.id}" /> <input type="text" name="name" value="${department.name}" />
								<button type="submit" class="btn btn-primary">修改部门名称</button>
							</form>
						</td>
						<td><a class="showDialog" href="javascript:void(0)">编辑</a> <s:url action="doRemoveDepartment" id="doRemoveDepartment" namespace="/security/department">
								<s:param name="id" value="id"></s:param>
							</s:url> <a class="confirm" title="删除当前部门" href="${doRemoveDepartment}">删除</a></td>
					</tr>
				</s:iterator>
			</tbody>
		</table>
	</tiles:putAttribute>
</tiles:insertDefinition>